/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gizmo;

import processing.core.PApplet;
import processing.core.PImage;

/**
 *
 * @author Steven
 */
public class ImageGizmo extends PApplet {
  public void setup() {
  PImage p1;
  
  p1=loadImage("http://img481.imageshack.us/img481/8459/cerrodemonserrate036s6hx.jpg");
  p1.resize(600, 600);

  int i,j;
  i=p1.width;
  j=p1.height;

  int n=20;//Dividirlo en n partes horizontales
  int m=20;//Dividirlo en m partes verticales
  int count=0;

  size(i,j);

  for(int k=0;k<n;k++){
	  int Wx=i/n;//Nuevo ancho
  	for(int l=0;l<m;l++){
  		int Hx=j/m;//Nuevo Alto
                count++;
  		PImage px=p1.get(Wx*k,Hx*l,Wx,Hx);//Trozo de la imagen
                System.out.print(count+"/"+(m*n)+" ");
  		Image aux = new Image(px);
  		px=aux.searchByColor();//Buscar una imagen analoga a la Mini imagen
                px.resize(Wx, Hx);
  		image(px,Wx*k,Hx*l, px.width, px.height);
  }}


  System.out.println("OK");

  noLoop();
}
  static public void main(String args[]) {
    PApplet.main(new String[] { "--bgcolor=#F0F0F0", "gizmo.ImageGizmo" });
  }
}